<?php
/**
 * Created by PhpStorm.
 * User: Inhere
 * Date: 2015/2/15
 * Time: 18:12
 * Use :
 * File: LogHelper.php
 */
namespace logs;

class LogHelper
{
    static public function createDir($dir, $mode=0775, $type = true)
    {
        return is_dir($dir) or ( self::createDir( dirname($dir) , $mode, $type ) and @mkdir($dir, $mode, $type));
    }

    /**
     * 信息格式化
     * @param array|string $context
     * @return string
     */
    static public function format($context)
    {
        if (!$context)
        {
            return '';
        }

        if (is_string($context))
        {
            return $context;
        }

        $info = '';

        foreach ($context as $key => $value)
        {
            $key    = $key==='' ? 'unknown':$key;
            $value  = $value==='' ? 'unknown':$value;
            $info   .= "\t".$key.' -- '.$value.PHP_EOL;
        }

        return PHP_EOL.$info;
    }

}// end class LogHelper